import {createRouter, createWebHistory} from 'vue-router';
import Login from '../components/Login.vue';
import Mainpage from '../components/Mainpage.vue';
import Register from '../components/Register.vue';
import CableSegmentDistribution from '../components/CableSegmentDistribution.vue';

const routes = [
    {
        path: '/login',
        name: 'Login',
        component: Login
    },
    {
        path: '/dashboard',
        name: 'Dashboard',
        component: Mainpage
    },
    {
        path: '/register',
        name: 'Register',
        component: Register
    },
    {
        path: '/cable-segment-distribution',
        name: 'CableSegmentDistribution',
        component: CableSegmentDistribution
    },
    // {
    //   path: '/',
    //   redirect: '/login'
    // },
    {
        path: '/',
        redirect: '/dashboard'
    }
];

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes
});

router.beforeEach((to, from, next) => {
    // // 检查目标路由是否是需要认证的页面 (例如: /dashboard)
    // const requiresAuth = to.path === '/dashboard';
    //
    // // 检查用户是否已登录 (这里需要根据实际情况修改，例如检查 localStorage 中的 token)
    // const isAuthenticated = localStorage.getItem('userToken'); // 示例：检查是否存在 token
    //
    // if (requiresAuth && !isAuthenticated) {
    //   // 如果需要认证但用户未登录，则重定向到登录页面
    //   next('/login');
    // } else {
    //   // 否则，允许导航继续
    //   next();
    // }
    next();
});

export default router;
